import { Injectable, NestMiddleware } from '@nestjs/common';
import { TakeToken } from 'src/utils/token';
import { RedisService } from 'src/redis/redis.service';
@Injectable()
export class CommonMiddleware implements NestMiddleware {
  async use(req: any, res: any, next: () => void) {
    if(req.headers.token){
      const token = await TakeToken(req.headers.token, 'token')
      const redisService = new RedisService()
      await redisService.setNS('token')
      const info = await redisService.get(token)
      req['tokenInfo'] = info
    }
    
    next();
  }
}
